package cj.web.lkg.dao;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

@DAO
public interface NewsOpDAO {

	//新闻点赞------------------
	@SQL("INSERT INTO Praises (newsId,newsTitle,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.newsId,:t.newsTitle,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createPraise(@SQLParam("t") Map rep);
	//新闻点赞size
	@SQL("SELECT count(1) FROM Praises WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
    int queryPraiseSize(int newsId,String userId);
	//删除新闻点赞
	@SQL("DELETE FROM Praises WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
	void delPraise(int newsId,String userId);
	//修改新闻赞数
	@SQL("update News set praiseNum=praiseNum+1 where id=:1")
    void addPraiseById(int id);
	//修改新闻赞数
	@SQL("update News set praiseNum=praiseNum-1 where id=:1")
    void subPraiseById(int id);
	
	//新闻收藏------------------
	@SQL("INSERT INTO Collect (newsId,newsTitle,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.newsId,:t.newsTitle,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createCollect(@SQLParam("t") Map rep);
	//新闻收藏size
	@SQL("SELECT count(1) FROM Collect WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
    int queryCollectSize(int newsId,String userId);
	//删除新闻收藏
	@SQL("DELETE FROM Collect WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
	void delCollect(int newsId,String userId);
	//修改新闻收藏数
	@SQL("update News set collectNum=collectNum+1 where id=:1")
    void addCollectById(int id);
	//修改新闻收藏数
	@SQL("update News set collectNum=collectNum-1 where id=:1")
    void subCollectById(int id);
	
	//新闻转发------------------
	@SQL("INSERT INTO Forward (newsId,newsTitle,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.newsId,:t.newsTitle,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createForward(@SQLParam("t") Map rep);
	//转发size
	@SQL("SELECT count(1) FROM Forward WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
    int queryForwardSize(int newsId,int userId);
	//修改新闻转发数
	@SQL("update News set forwardNum=forwardNum+1 where id=:1")
    void addForwardById(int id);
	
	//新闻评论------------------
	@SQL("SELECT id,newsId,newsTitle,userId,userName,contents,isAnonymous,releaseState,reply,replyUserId,replyName,editReplyUserId,editReply,deleteFlag,createUser,createAt,updateUser,updateAt,praiseNum FROM Comments WHERE deleteFlag=1 AND releaseState =1 AND newsId =:1  #if(:4==0){  ORDER BY stickAt DESC,createAt DESC } #if(:4==1){  ORDER BY praiseNum DESC } LIMIT :2,:3 ")
	List<Map> queryComments(int newsId,int start,int length,int order,String createAt);
	//新闻评论size
	@SQL("SELECT count(1) FROM Comments WHERE deleteFlag=1 AND releaseState =1 AND newsId=:1 AND createAt<:2")
    int queryCommentsSize(int newsId,String createAt);
	//新闻评论size
	@SQL("SELECT * FROM Comments WHERE id=:1")
	List<Map> queryCommentsById(int id);
	//添加评论
	@SQL("INSERT INTO Comments (newsId,newsTitle,contents,isAnonymous,releaseState,reply,replyUserId,replyName,deleteFlag,createUser,createAt,praiseNum) VALUES (:t.newsId,:t.newsTitle,:t.contents,:t.isAnonymous,0,:t.reply,:t.replyUserId,:t.replyName,1,:t.createUser,now(),0)")
	void createComments(@SQLParam("t") Map rep);
	//添加评论ByEditReply
	@SQL("INSERT INTO Comments (newsId,newsTitle,contents,isAnonymous,releaseState,reply,replyUserId,replyName,editReplyUserId,editReply,praiseNum,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.newsId,:t.newsTitle,:t.contents,:t.isAnonymous,0,:t.reply,:t.replyUserId,:t.replyName,:t.editReplyUserId,:t.editReply,0,1,:t.createUser,now(),:t.updateUser,now()) ")
	void createCommentsByEditReply(@SQLParam("t") Map rep);
	//删除评论
	@SQL("update Comments set deleteFlag=0 where id=:1")
    void delCommentsById(int id);
	//修改新闻评论数
	@SQL("update News set commentsNum=commentsNum+1 where id=:1")
    void addCommentsById(int id);
	//修改新闻评论数
	@SQL("update News set commentsNum=commentsNum-1 where id=:1")
    void subCommentsById(int id);
	
	//新闻评论点赞------------------
	@SQL("INSERT INTO CommentsPraises (newsId,commentsId,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.newsId,:t.commentsId,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createCommentsPraise(@SQLParam("t") Map rep);
	//新闻点赞size
	@SQL("SELECT count(1) FROM CommentsPraises WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 AND commentsId=:3 ")
    int queryCommentsPraiseSize(int newsId,int userId,int commentsId);
	//删除新闻点赞
	@SQL("DELETE FROM CommentsPraises WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 AND commentsId=:3 ")
	void delCommentsPraise(int newsId,int userId,int commentsId);
	//修改新闻赞数
	@SQL("update Comments set praiseNum=praiseNum+1 where id=:1")
    void addCommentsPraiseById(int id);
	//修改新闻赞数
	@SQL("update Comments set praiseNum=praiseNum-1 where id=:1")
    void subCommentsPraiseById(int id);
	
	//新闻浏览---------------------
	@SQL("INSERT INTO PV (userId,userName,newsId,newsTitle,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.userId,:t.userName,:t.newsId,:t.newsTitle,1,:t.createUser,now(),:t.updateUser,now())")
	void createNewsPV(@SQLParam("t") Map rep);
	//查询浏览
	@SQL("SELECT count(1) FROM PV WHERE deleteFlag=1 AND newsId=:1 AND userId=:2 ")
    int queryNewsPVSize(int newsId,int userId);
	//修改新闻浏览数
	@SQL("update News set pvNum=pvNum+1,pvNumFinal=pvNumFinal+1 where id=:1")
    void addNewsPVById(int id);
}
